package com.koron.common.core.base;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

@Slf4j
public abstract class ServiceTemplate<R, T> {

    public R execute(T request) {
        log.info("start invoke, request: " + request);
        try {
            // 参数校验
            validate(request);

            // 执行业务逻辑
            R response = doProcess(request);
            log.info("end invoke, response: " + response);
            return response;
        } catch (Exception e) {
            // 打印错误
            log.error("error invoke,request: " + request + ",exception message=" +  Arrays.toString(e.getStackTrace()));
            return null;
        }
    }

    protected abstract R doProcess(T request);

    protected abstract void validate(T request);
    
    
}
